package com.sbs.gaoxinqutoilet.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.bumptech.glide.Glide;
import com.sbs.gaoxinqutoilet.R;
import com.sbs.gaoxinqutoilet.entity.HomeMenuEntity;

import java.util.List;

/**
 * Created by 聪明一只哈 on 2019/10/28.
 * Time: 2019/10/28  16:07
 */
public class ChanelAdapter extends DelegateAdapter.Adapter {

    private Context mContext;
    private LayoutHelper mLayoutHelper;
    private List<HomeMenuEntity> mItemChanelList;
    private LayoutInflater inflater;

    public ChanelAdapter(Context mContext, LayoutHelper mLayoutHelper, List<HomeMenuEntity> mItemChanelList) {
        this.mContext = mContext;
        this.mLayoutHelper = mLayoutHelper;
        this.mItemChanelList = mItemChanelList;
        inflater = LayoutInflater.from(mContext);

    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mLayoutHelper;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new ChanelViewHolder(inflater.inflate(R.layout.vlayout_chanel_item, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {


        ChanelViewHolder chanelViewHolder = (ChanelViewHolder) viewHolder;
        final HomeMenuEntity channelInfoBean = mItemChanelList.get(i);


        switch(channelInfoBean.getFunc_id()){
            case "201":
                //helper.getView(R.id.image_home_menu).setBackgroundResource(R.drawable.file);
                Glide.with(mContext).load(R.drawable.file)
                        .into(chanelViewHolder.imgThumb);
                chanelViewHolder.tvTitle.setText("档案管理");

                break;
            case "205":
                //helper.getView(R.id.image_home_menu).setBackgroundResource(R.drawable.home_rebuild);
                Glide.with(mContext).load(R.drawable.home_rebuild)
                        .into(chanelViewHolder.imgThumb);
                chanelViewHolder.tvTitle.setText("施工登记");

                break;
            case "202":
                //helper.getView(R.id.image_home_menu).setBackgroundResource(R.drawable.acceptance);
                Glide.with(mContext).load(R.drawable.acceptance)
                        .into(chanelViewHolder.imgThumb);

                chanelViewHolder.tvTitle.setText("户厕验收");
                break;
            case "401":
                //helper.getView(R.id.image_home_menu).setBackgroundResource(R.drawable.filecheck);
                Glide.with(mContext).load(R.drawable.filecheck)
                        .into(chanelViewHolder.imgThumb);

                chanelViewHolder.tvTitle.setText("户厕检查");
                break;
            case "306":
                //helper.getView(R.id.image_home_menu).setBackgroundResource(R.drawable.tongji);
                Glide.with(mContext).load(R.drawable.tongji)
                        .into(chanelViewHolder.imgThumb);

                chanelViewHolder.tvTitle.setText("户厕统计");
                break;

            default:

                break;
        }


        //chanelViewHolder.tvTitle.setText(channelInfoBean.getFunc_name());

        chanelViewHolder.layout_hori.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(chanelClicker!=null){
                    chanelClicker.clickCallBack(channelInfoBean);
                }
            }
        });


    }


    @Override
    public int getItemCount() {
        return mItemChanelList == null ? 0 : mItemChanelList.size();
    }

    static class ChanelViewHolder extends RecyclerView.ViewHolder {

        private ImageView imgThumb;
        private TextView tvTitle;
        private LinearLayout layout_hori;

        public ChanelViewHolder(View itemView) {
            super(itemView);
            imgThumb = (ImageView) itemView.findViewById(R.id.img_thumb);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
            layout_hori = (LinearLayout) itemView.findViewById(R.id.layout_hori);
        }
    }

    public interface ChanelClicker{
        void clickCallBack(HomeMenuEntity channelInfoBean);
    }

    private ChanelClicker chanelClicker;

    public void setChanelClicker(ChanelClicker chanelClicker){
        this.chanelClicker=chanelClicker;
    }
}
